'use strict';

const expressConfig = require('./config/env/express.json'),
  mongoose = require('./config/mongoose.js'),
  app = require('./config/express.js');  //Pay attention to first scan mongoose'model, than scasn express's route

const http = require('http'),
      server = http.createServer(app);


const io = require('socket.io')(server);
io.on('connection', function(socket) {
    console.log(socket.client.id + " connented")

    socket.on('hi', function(data) {
        socket.broadcast.emit('bubble','change your bubble!')
    })

    socket.on('disconnect', function(data) {
        console.log('断开',data)
        socket.emit('leave','离开');
    })
});

app.set('port', expressConfig.A_BACKEND.port);

server.listen(app.get('port'), function () {
  console.log('Express server listening on port ' + server.address().port);
});

module.exports = app;

